package com.pro.springbootshop.service.impl;

import com.pro.springbootshop.entity.MainClasses;
import com.pro.springbootshop.mapper.MainClassesMapper;
import com.pro.springbootshop.service.MainClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MainClassesServiceImpl implements MainClassesService {
    public MainClassesMapper mainClassesMapper;
    @Autowired
    public void setUserMapper (MainClassesMapper mainClassesMapper) {
        this.mainClassesMapper = mainClassesMapper;
    }
    @Override
    public String saveMainClasses(String mainClassName) {
        MainClasses mainClasses=new MainClasses();
        mainClasses.setMainClassName(mainClassName);
        if(mainClassesMapper.selectMainClassByName(mainClassName)==null){
            int i=mainClassesMapper.insert(mainClasses);
            if(i>0){
                return "插入成功";
            }else{
                return "插入失败";
            }
        }else{
            return "已存在";
        }
    }

    @Override
    public String deleteMainClasses(int mainClassId) {
        int i=mainClassesMapper.deleteById(mainClassId);
        if(i>0){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }

    @Override
    public List<MainClasses> findAllByMain() {
        return mainClassesMapper.selectAllByMain();
    }
}
